package mysql

import "gorm.io/gorm"

type Good struct {
	gorm.Model
	UserId    int     `gorm:"type:int(10);not null;comment:'用户Id'"`
	GoodTitle string  `gorm:"type:varchar(20);not null;comment:'商品标题'"`
	GoodStock int     `gorm:"type:int(10);not null;comment:'商品库存'"`
	GoodNum   int     `gorm:"type:int(10);not null;comment:'商品数量'"`
	GoodPrice float64 `gorm:"type:double(10,2);not null;comment:'商品价格'"`
}

type User struct {
	gorm.Model
	Account  string `gorm:"type:varchar(20);not null;comment:'用户名称'"`
	Password string `gorm:"type:char(32);not null;comment:'用户密码'"`
}

func (g *Good) Create() error {
	return DB.Create(&g).Error
}

func (g *Good) GetGood(id int) error {
	return DB.Where("id = ?", id).Limit(1).Find(&g).Error
}
